#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <cstdlib>
#include <map>
#include <bitset>
#include <unordered_map>
#include <ctime>
#include <vector>
#include <queue>
#include <list>
#include <stack>

#define R register
#define L long
#define LL long long
#define I inline
#define U unsigned
using namespace std;
I LL read()
{
    R LL   x;
    R bool f;
    R char c;
    for(f=0;(c=getchar())<'0'||c>'9';f=c=='-');
    for(x=c-'0';(c=getchar())>='0'&&c<='9';x=(x<<3)+(x<<1)+c-'0');
    return f?-x:x;
}
#define MAXN 111
int a[MAXN],b[MAXN];
int main()
{
    freopen("7-3.in","r",stdin);
    //freopen("7-3.out","w",stdout);
    int     n=read();
    for(int i=0;i<n;a[i]=read(),++i);
    for(int i           =0;i<n;b[i]=read(),++i);
    bool    flag        =true;
    int     ns          =1;
    for(;ns<n;++ns)
        if(b[ns-1]>b[ns])
            break;
    for(int i=ns;i<n;++i)
        if(a[i]!=b[i])
        {
            flag=false;
            break;
        }
    if(flag)
    {
        printf("Insertion Sort\n");
        if(ns!=n)
            sort(b,b+ns+1);
    }
    else
    {
        printf("Heap Sort\n");
        int i=n-1;
        for(;i>0&&b[i]>b[i-1];--i);
        //直接使用STL
        //pop_heap(b, b + i + 1);
        //手写堆排序
        swap(b[0],b[i]);
        for(int j=0;j<i;)
        {
            int k=((j+1)<<1)-1;
            if(k+1<i&&b[k+1]>b[k])
                k=k+1;
            if(k>=i||b[j]>=b[k])
                break;
            swap(b[j],b[k]);
            j=k;
        }
    }
    
    
    for(int i=0;i<n;printf("%s%d",i?" ":"",b[i]),++i);
    
    fclose(stdin);
    fclose(stdout);
    return 0;
}